﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Data.Entity;

namespace AsyncDemo.Model
{
    public class Blog
    {
        /// <summary>
        /// 设置PrimKey  为主键
        /// </summary>
        [Key]
        public int BlogId { get; set; }

        /// <summary>
        /// 必填
        /// </summary>
        [Required]
        [MinLength(10,ErrorMessage="博客标题最短不能低于10个字符"),MaxLength(100,ErrorMessage="博客标题最长不能超过100个字符")]
        public string Title { get; set; }

        [Required]
        public string Author { get; set; }

        [MaxLength(500,ErrorMessage="博客内容最长不能超过500个字符")]
        public string Content { get; set; }

        /// <summary>
        /// ConcurrencyCheck 批注可以标记一个或多个要在进行并发检查数据库中，当用户编辑或删除的实体的属性
        /// </summary>
        [ConcurrencyCheck, MaxLength(10, ErrorMessage = "BloggerName must be 10 characters or less")]
        public string BloggerName { get; set; }


        //public string Name { get; set; }

        public string Url { get; set; }
        public virtual ICollection<Post> Posts { get; set; }

        /// <summary>
        /// 博客详情(值对象)，创建的数据库字段带有BlogDetail前缀
        /// </summary>
        public BlogDetails BlogDetail { get; set; }

        /// <summary>
        /// 博客列表显示之用，不进行数据库映射
        /// </summary>
        [NotMapped]
        public string ListDisplayName
        {

            get { return Title.Substring(0,Title.Length>20?20:Title.Length) + "... [ " + Author + " ] "; }
        }
    }
}
